package com.jida.hadoop.mr.join;

import com.jida.hadoop.mr.tools.TProperties;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
 
import java.io.IOException;
 
/**
 * 产品匹配：关联产品地址库，标识用户行为匹配中的产品地址
 */
public class MapperDxProMatch extends Mapper<LongWritable,Text,Text,Text>{
    Text ok = new Text();
    Text ov = new Text();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] vs = value.toString().split(TProperties.getValue("fileoutsplit"));
        if(vs.length==5 && Integer.parseInt(vs[2].toString())==1){//2的结果而且是产品
            String ku = vs[0]/*+","+"u"*/;//行为ID
            String vu = vs[1]+"|";//用户ID
            ok.set(ku);
            ov.set(vu);
            context.write(ok,ov);
        }else if(vs.length==9){
            String kp = vs[0]/*+","+"p"*/;//行为ID
            String vp = value.toString().substring(19);//行为ID之后的数据（产品的具体信息）
            ok.set(kp);
            ov.set(vp);
            context.write(ok,ov);
        }
    }
}
